import os
from ..common import (
  getJSONData
)
# 与区域无用的键值
REGION_NODE_USELESS_KEY = [
    "disabled", "cardSlugs", "onToastSelectEvents"
]
# 对区域有用的键值
REGION_NODE_USEFUL_KEY = [
    "slug", 
    "crestImage", 
    "toastBackground", 
    "flyoutBackground", 
    "backgroundImage", 
    "title", 
    "subtitle", 
    "description", 
    "link"
]
# 与其他节点相关的键值
REGION_NODE_RELATIONSHIP_KEY = [
  "facts", "championSlugs"
]

# 需要甄别单一区域的键值，这个键值表示该数据为单一城市
# 因为数据集当中有些并不属于一个地方，会和起来好几个地方，导致数据不一致
VERIFY_CITY_SINGLE_KEY = "championSlugs"
# 关于涉及到新的结点的键值
ABOUT_OTHER_NEW_NODE_KEY = "facts"

# 数据的路径
DATA_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../data/region')) + '/'


# 获取区域所有有效数据
def getRegionData():
    all_region_data = getJSONData('region_data.json', DATA_PATH)
    result = []
    count = 1
    # 删除掉一些不要的数据
    for region_key in all_region_data: 
        # print("="*20 + "第" + str(count) + "条数据" + "="*20)
        count+=1
        region_data = all_region_data[region_key] 
        # print(region_data)
        # 没有championSlugs说明是多个区域一起形成的数据，过滤掉
        if VERIFY_CITY_SINGLE_KEY not in region_data:
            continue
        for key in REGION_NODE_USELESS_KEY:
            # 如果有这个无效的key，就把这些数据丢掉
            if key in region_data:
                region_data.pop(key)
        result.append(region_data)
    return result

# 用来查看某种类型的结点有多少种值
# 主要有以下四种
'''
"manageSystem": {
    "type": "manageSystemNode",
    "desc": "统治管理"
},
"magicalAttitude": {
    "type": "magicalAttitudeNode",
    "desc": "对魔法的态度"
},
"technologicalLevel": {
    "type": "technologicalLevelNode",
    "desc": "科技水平"
},
"environment": {
    "type": "environmentNode",
    "desc": "总体环境"
}
'''
def lookNodeType():
    all_data = getRegionData()
    manageSystem = set()
    magicalAttitude = set()
    technologicalLevel = set()
    environment = set()
    for current_data in all_data:
        # 以上四个内容都在这个键里面
        if ABOUT_OTHER_NEW_NODE_KEY not in current_data:
            continue
        for item in current_data[ABOUT_OTHER_NEW_NODE_KEY]:
            if item['label'] == "统治管理":
                manageSystem.add(item['description'])
            elif item['label'] == "对魔法的态度":
                magicalAttitude.add(item['description'])
            elif item['label'] == "科技水平":
                technologicalLevel.add(item['description'])
            else:
                environment.add(item['description'])

# 获取魔法态度节点类型数据
def getMagicalAttitudeData():
  magical_attitude_data = getJSONData('magical_attitude_node.json', DATA_PATH)
  return magical_attitude_data

# 获取管理制度节点类型数据
def getManageSystemData():
  manage_system_data = getJSONData('manage_system_node.json', DATA_PATH)
  return manage_system_data

# 获取环境节点类型数据
def getEnvironmentData():
  environment_data = getJSONData('environment_node.json', DATA_PATH)
  return environment_data

# 获取科技水平节点类型数据
def getTechnologicalLevelData():
  technological_level_node = getJSONData('technological_level_node.json', DATA_PATH)
  return technological_level_node

